/**
 * Created by yanweiqiang on 2016/6/29 0029.
 */
function ChatMessage() {
    this.db = require('mongoskin').db('mongodb://localhost:27017/sayhichat');
    this.mm = this.db.collection('message');

    this.insert = function (data, callback) {
        this.mm.insert(data, function (err, result) {
            if (err) {
                throw err;
            }

            if (result) {
                console.log("added");
                callback(result.ops[0]);
            }
        });
    };

    this.updateStatus = function (uuid, status) {
        var where = '{uuid:' + uuid + '}';
        var change = '{$set:{status:' + status + '}}';
        this.mm.update(where, change, function (err, result) {
            if (!err) console.log('status updated!');
        });
    }
}

module.exports = ChatMessage;